//
//  CommonMacro.h
//  HZLWeiBo
//
//  Created by SDMac on 15/6/25.
//  Copyright (c) 2015年 SDMac. All rights reserved.
//
// 常用宏定义


/*--------------------打印开关-----------------*/

#ifdef DEBUG  // 调试状态,打开LOG功能

#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#define MLog(...) printf("%s [Line %d] %s\n",__PRETTY_FUNCTION__,__LINE__,[[NSString stringWithFormat:__VA_ARGS__] UTF8String]);

#else // 发布状态,关闭LOG功能

#define DLog(fmt, ...)

#define MLog(...)

#endif

/*--------------------方法简写-----------------*/

/** 获得程序代理 */
#define hAppDelegate [UIApplication sharedApplication].delegate

/** 获得程序根视图 */
#define hRootController [UIApplication sharedApplication].delegate.window.rootViewController

/** 获取程序版本号 */
#define hAPPVERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]

/*--------------------操作系统相关-----------------*/

/** 判断系统版本 */
#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
#define iOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0)
#define iOS9 ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0)
#define iOS10 ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0)
#define iOS11 ([[UIDevice currentDevice].systemVersion doubleValue] >= 11.0)

/** 是否为苹果5或5s */
#define IS_IPHONE_5 ([UIScreen mainScreen].bounds.size.height == 568.0)
#define IS_IPHONE_6P ([UIScreen mainScreen].bounds.size.width == 414.0)

/*--------------------屏幕坐标相关-----------------*/

/** 物理屏幕的宽 */
#define hScreenWidth [UIScreen mainScreen].bounds.size.width

/** 物理屏幕的高 */
#define hScreenHeight [UIScreen mainScreen].bounds.size.height

// iPhone X 适配相关
#define hStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define hNavBarHeight 44.0
#define hTabBarHeight 49
#define hBottomHeight ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 83:49)
#define hTopHeight (hStatusBarHeight + hNavBarHeight)
#define hScale (hScreenWidth / hScreenHeight)

#define kIphone4 (kScreenWidth == 320.0&&kScreenHeight==480.0)?YES:NO
#define kIphone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define kIphone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define kIphone6p ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define kIphoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define KIphoneXMAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)
#define KIphoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1624), [[UIScreen mainScreen] currentMode].size)||CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size)) : NO)

#define kNaviHeight self.navigationController.navigationBar.height + CGRectGetHeight([UIApplication sharedApplication].statusBarFrame)

#define KIphoneFullScreen (kIphoneX||KIphoneXMAX||KIphoneXR)
#define kIPhoneX_BOTTOM_HEIGHT  (KIphoneFullScreen?34:0)
#define kIPhoneX_TOP_HEIGHT  (KIphoneFullScreen?24:0)

/*--------------------颜色相关-----------------*/

/**  随机色(arc4random_uniform(255)获取255以内的无符号随机数) */
#define RandomColor [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1]

/** RGB设置颜色 */
#define RGB_COLOR(a,b,c,d) [UIColor colorWithRed:a/255.0 green:b/255.0 blue:c/255.0 alpha:d]

/*--------------------字体设置-----------------*/

/** 设置字体大小*/
#define FONT_SIZE(s)  [UIFont systemFontOfSize:(s)]

/** 设置字体和字体大小 */
#define FONT_NAMESIZE(a,b)  [UIFont fontWithName:a size:b]

/*--------------------画分割线-----------------*/

/** 正确画一个像素的宏 */
#define SINGLE_LINE_WIDTH (1 / [UIScreen mainScreen].scale)
#define SINGLE_LINE_ADJUST_OFFSET ((1 / [UIScreen mainScreen].scale) / 2)
